package cheqex.update;

import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;

import cheqex.update.controllers.ActivitiesController;

public class ActivitiesView extends JPanel {
	private JLabel datelabel;
	private JLabel date1;
	private JLabel date2;
	private JLabel date3;
	private JLabel date4;
	private JLabel date5;
	
	private JLabel act;
	private JLabel act1;
	private JLabel act2;
	private JLabel act3;
	private JLabel act4;
	private JLabel act5;
	
	public ActivitiesView(){
		latestActivities();
	}
	
	private void latestActivities(){
		int n = ActivitiesController.getID();
		String date;
		String activity;
		System.out.print(n);
		
		datelabel = new JLabel("Date/Time:");
		act = new JLabel("Action:");
		this.add(datelabel);
		this.add(act);
		
		boolean empty = true;
		
		date = ActivitiesController.getDate(n);
		activity = ActivitiesController.getActivity(n);
		if(date!=null && activity!=null){
			date1 = new JLabel(date);
			act1 = new JLabel(activity);
			this.add(date1);
			this.add(act1);
			empty = false;
		}
		
		date = ActivitiesController.getDate(n-1);
		activity = ActivitiesController.getActivity(n-1);
		if(date!=null && activity!=null){
			date2 = new JLabel(date);
			act2 = new JLabel(activity);
			this.add(date2);
			this.add(act2);
			empty = false;
		}
		
		date = ActivitiesController.getDate(n-2);
		activity = ActivitiesController.getActivity(n-2);
		if(date!=null && activity!=null){
			date3 = new JLabel(date);
			act3 = new JLabel(activity);
			this.add(date3);
			this.add(act3);
			empty = false;
		}
		
		date = ActivitiesController.getDate(n-3);
		activity = ActivitiesController.getActivity(n-3);
		if(date!=null && activity!=null){
			date4 = new JLabel(date);
			act4 = new JLabel(activity);
			this.add(date4);
			this.add(act4);
			empty = false;
		}
	
		date = ActivitiesController.getDate(n-4);
		activity = ActivitiesController.getActivity(n-4);
		if(date!=null && activity!=null){
			date5 = new JLabel(date);
			act5 = new JLabel(activity);
			this.add(date5);
			this.add(act5);
			empty = false;
		}
		
		if(empty){
			this.setVisible(false);
		}else this.setVisible(true);
			
		this.setLayout(new GridLayout(6,2,0,3));
	}
}
